<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: WebAPI::Delicious</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">WebAPI::Delicious</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/webapi/delicious_rb.html">
                webapi/delicious.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                Object
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
This class allows you to access and manipulate your del.icio.us bookmarks
through JSON feed or del.icio.us API. If you provides your password to
constructor, <a href="Delicious.html">WebAPI::Delicious</a> uses
del.icio.us API to get full access to your all bookmarks. otherwise, It
uses JSON feed to obtain your public bookmarks.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000024">add_post</a>&nbsp;&nbsp;
      <a href="#M000026">delete_post</a>&nbsp;&nbsp;
      <a href="#M000028">get_bundles</a>&nbsp;&nbsp;
      <a href="#M000025">get_posts</a>&nbsp;&nbsp;
      <a href="#M000027">get_tags</a>&nbsp;&nbsp;
      <a href="#M000023">new</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="Util.html">Util</a></span>
      </div>
    </div>

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000023" class="method-detail">
        <a name="M000023"></a>

        <div class="method-heading">
          <a href="#M000023" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(username, password = nil, limiter = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Create an instance of <a href="Delicious.html">WebAPI::Delicious</a>.
</p>
<dl>
<dt>username</dt><dd>Required. The login name of your del.icio.us account.

</dd>
<dt>password</dt><dd>Optional. The password of your del.icio.us account. If you omit this
argument, <a href="Delicious.html">WebAPI::Delicious</a> will use JSON feed
for query. In this case, you can access only your public bookmarks, and
some methods are not available.

</dd>
<dt>limiter</dt><dd>Optional. An object for managing interval of each request. del.icio.us API
client must wait at least one second between queries or your IP address is
going to be banned. If you omit this argument, an appropriate object would
be selected automatically. See LimiterBase for details.

</dd>
</dl>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000023-source">
<pre>
    <span class="ruby-comment cmt"># File webapi/delicious.rb, line 65</span>
65:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">username</span>, <span class="ruby-identifier">password</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">limiter</span> = <span class="ruby-keyword kw">nil</span>)
66:       <span class="ruby-ivar">@limiter</span>  = <span class="ruby-identifier">limiter</span>
67:       <span class="ruby-ivar">@username</span> = <span class="ruby-identifier">username</span>.<span class="ruby-identifier">to_s</span>
68:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">password</span>
69:         <span class="ruby-identifier">protocol</span>  = <span class="ruby-constant">REST</span>.<span class="ruby-identifier">https</span>(<span class="ruby-value str">'api.del.icio.us'</span>)
70:         <span class="ruby-identifier">auth</span>      = <span class="ruby-constant">REST</span>.<span class="ruby-identifier">basic_auth</span>(<span class="ruby-identifier">username</span>, <span class="ruby-identifier">password</span>);
71:         <span class="ruby-ivar">@api_mode</span> = <span class="ruby-keyword kw">true</span>
72:         <span class="ruby-ivar">@limiter</span>  = <span class="ruby-constant">DefaultLimiter</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@limiter</span>
73:       <span class="ruby-keyword kw">else</span>
74:         <span class="ruby-identifier">protocol</span>  = <span class="ruby-constant">REST</span>.<span class="ruby-identifier">http</span>(<span class="ruby-value str">'del.icio.us'</span>)
75:         <span class="ruby-identifier">auth</span>      = <span class="ruby-keyword kw">nil</span>
76:         <span class="ruby-ivar">@api_mode</span> = <span class="ruby-keyword kw">false</span>
77:         <span class="ruby-ivar">@limiter</span>  = <span class="ruby-constant">NullLimiter</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@limiter</span>
78:       <span class="ruby-keyword kw">end</span>
79:       <span class="ruby-ivar">@rest</span>     = <span class="ruby-constant">REST</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">protocol</span>, <span class="ruby-identifier">auth</span>)
80:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000024" class="method-detail">
        <a name="M000024"></a>

        <div class="method-heading">
          <a href="#M000024" class="method-signature">
          <span class="method-name">add_post</span><span class="method-args">(post, replace = true, shared = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000024-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000024-source">
<pre>
    <span class="ruby-comment cmt"># File webapi/delicious.rb, line 82</span>
82:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_post</span>(<span class="ruby-identifier">post</span>, <span class="ruby-identifier">replace</span> = <span class="ruby-keyword kw">true</span>, <span class="ruby-identifier">shared</span> = <span class="ruby-keyword kw">true</span>)
83:       <span class="ruby-identifier">raise</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@api_mode</span>
84:       <span class="ruby-identifier">params</span> = {
85:         <span class="ruby-value str">'url'</span>         =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">string_param</span>(<span class="ruby-identifier">post</span>, <span class="ruby-identifier">:url</span>),
86:         <span class="ruby-value str">'description'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">string_param</span>(<span class="ruby-identifier">post</span>, <span class="ruby-identifier">:title</span>),
87:         <span class="ruby-value str">'extended'</span>    =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">string_param</span>(<span class="ruby-identifier">post</span>, <span class="ruby-identifier">:notes</span>),
88:         <span class="ruby-value str">'dt'</span>          =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">date_param</span>(<span class="ruby-identifier">post</span>, <span class="ruby-identifier">:date</span>),
89:         <span class="ruby-value str">'tags'</span>        =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">tags_param</span>(<span class="ruby-identifier">post</span>, <span class="ruby-identifier">:tags</span>),
90:         <span class="ruby-value str">'replace'</span>     =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">replace</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-value str">'no'</span>,
91:         <span class="ruby-value str">'shared'</span>      =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">shared</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-value str">'no'</span>
92:       }.<span class="ruby-identifier">delete_if</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span> <span class="ruby-constant">NilClass</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">value</span> <span class="ruby-keyword kw">end</span>
93:       <span class="ruby-identifier">doc</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">http_post</span>(<span class="ruby-value str">'/v1/posts/add'</span>, <span class="ruby-identifier">params</span>))
94:       <span class="ruby-identifier">raise</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'code'</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'done'</span>
95:       <span class="ruby-keyword kw">nil</span>
96:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000026" class="method-detail">
        <a name="M000026"></a>

        <div class="method-heading">
          <a href="#M000026" class="method-signature">
          <span class="method-name">delete_post</span><span class="method-args">(opt = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000026-source">
<pre>
     <span class="ruby-comment cmt"># File webapi/delicious.rb, line 102</span>
102:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_post</span>(<span class="ruby-identifier">opt</span> = {})
103:       <span class="ruby-identifier">raise</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@api_mode</span>
104:       <span class="ruby-identifier">url</span> = <span class="ruby-identifier">string_param</span>(<span class="ruby-identifier">opt</span>, <span class="ruby-identifier">:url</span>)
105:       <span class="ruby-identifier">params</span> = {}
106:       <span class="ruby-identifier">params</span>[<span class="ruby-value str">'url'</span>] = <span class="ruby-identifier">url</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">url</span>
107:       <span class="ruby-identifier">doc</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">http_get</span>(<span class="ruby-value str">'/v1/posts/delete'</span>, <span class="ruby-identifier">params</span>))
108:       <span class="ruby-identifier">raise</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">root</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'code'</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">'done'</span>
109:       <span class="ruby-keyword kw">nil</span>
110:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000028" class="method-detail">
        <a name="M000028"></a>

        <div class="method-heading">
          <a href="#M000028" class="method-signature">
          <span class="method-name">get_bundles</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000028-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000028-source">
<pre>
     <span class="ruby-comment cmt"># File webapi/delicious.rb, line 116</span>
116:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_bundles</span>
117:       <span class="ruby-identifier">raise</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@api_mode</span>
118:       <span class="ruby-identifier">doc</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">http_get</span>(<span class="ruby-value str">'/v1/tags/bundles/all'</span>, {}))
119:       <span class="ruby-identifier">bundles</span> = {}
120:       <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">elements</span>.<span class="ruby-identifier">each</span>(<span class="ruby-value str">'bundles/bundle'</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span>
121:         <span class="ruby-identifier">name</span> = <span class="ruby-identifier">string_result</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'name'</span>])
122:         <span class="ruby-identifier">bundles</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">tags_result</span>(<span class="ruby-identifier">e</span>.<span class="ruby-identifier">attributes</span>[<span class="ruby-value str">'tags'</span>]) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">name</span>
123:       <span class="ruby-keyword kw">end</span>
124:       <span class="ruby-identifier">bundles</span>
125:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000025" class="method-detail">
        <a name="M000025"></a>

        <div class="method-heading">
          <a href="#M000025" class="method-signature">
          <span class="method-name">get_posts</span><span class="method-args">(opt = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000025-source">
<pre>
     <span class="ruby-comment cmt"># File webapi/delicious.rb, line 98</span>
 98:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_posts</span>(<span class="ruby-identifier">opt</span> = {})
 99:       <span class="ruby-ivar">@api_mode</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">get_posts_api</span>(<span class="ruby-identifier">opt</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">get_posts_json</span>(<span class="ruby-identifier">opt</span>)
100:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000027" class="method-detail">
        <a name="M000027"></a>

        <div class="method-heading">
          <a href="#M000027" class="method-signature">
          <span class="method-name">get_tags</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000027-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000027-source">
<pre>
     <span class="ruby-comment cmt"># File webapi/delicious.rb, line 112</span>
112:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_tags</span>
113:       <span class="ruby-ivar">@api_mode</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">get_tags_api</span>() <span class="ruby-operator">:</span> <span class="ruby-identifier">get_tags_json</span>()
114:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>